//
//  AddMatePopView.m
//  TQY
//
//  Created by 甘世清 on 2024/10/3.
//

#import "AddMatePopView.h"

@implementation AddMatePopView

- (void)SQ_UIViewForSelfView{
    self.backgroundColor = UIColor.whiteColor;
    self.layer.cornerRadius = 30;
    UILabel * label = [[UILabel alloc]init];
    label.text = SQNSLocalString(@"搭一手");
    label.textColor = SQColor333333;
    label.font = FONT_MEDIUM(16);
    [self addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self).offset(24);
    }];
    
    [self addSubview:self.fsTextView];
    [self.fsTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.mas_equalTo(SCREEN_WIDETH-40);
        make.height.mas_equalTo(140);
        make.top.equalTo(self).offset(60);
    }];
    [self addSubview:self.addButton];
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.width.mas_equalTo(SCREEN_WIDETH-40);
            make.height.mas_equalTo(50);
            make.top.equalTo(self.fsTextView.mas_bottom).offset(40);
    }];
    self.addButton.backgroundColor = SQHexColor(@"#3DA59D", 0.4);
    self.addButton.textColor = SQColor(@"#666666");
    self.addButton.SQTouchBtn.hidden = YES;
   
    WS(weakSelf);
    [self.fsTextView addTextDidChangeHandler:^(FSTextView *textView) {
        if ([textView.formatText isNotEmpty]) {
            weakSelf.addButton.backgroundColor = SQColor3DA59D;
            weakSelf.addButton.textColor = SQColor(@"#FFFFFF");
            weakSelf.addButton.SQTouchBtn.hidden = NO;
        } else {
            weakSelf.addButton.backgroundColor = SQHexColor(@"#3DA59D", 0.4);
            weakSelf.addButton.textColor = SQColor(@"#666666");
            weakSelf.addButton.SQTouchBtn.hidden = YES;
        }
    }];
    [self.fsTextView becomeFirstResponder];
    [self.addButton setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf endEditing:YES];
        [weakSelf SQ_shengqing];
    }];
}
- (void)setModel:(MateModel *)model{
    _model = model;
}
-(void)SQ_shengqing{
    if (![self.fsTextView.formatText isNotEmpty]) {
        [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"说点什么来打动搭主吧!")];
        return;
    }
    WS(weakSelf);
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:self.model.userid forKey:@"id"];
    [dic setObject:self.fsTextView.text forKey:@"content"];
    [HttpTool post:@"lug/apply" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        if (weakSelf.addMatetouchBlock) {
            weakSelf.addMatetouchBlock();
        }
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
   
}
 
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self endEditing:YES];
}
-(FSTextView*)fsTextView{
    if (!_fsTextView) {
        _fsTextView = [FSTextView textView];
        _fsTextView.font = FONT_REGULAR(14);
        _fsTextView.textColor = UIColor.blackColor;
        _fsTextView.backgroundColor = UIColor.whiteColor;
        _fsTextView.layer.cornerRadius = 8;
        _fsTextView.placeholder = SQNSLocalString(@"说点让搭主心动的~");
        _fsTextView.placeholderColor = SQHexColor(@"#3DA59D", 0.5);
        _fsTextView.placeholderFont = FONT_REGULAR(13);
        _fsTextView.layer.masksToBounds = YES;
        _fsTextView.layer.borderWidth = 1;
        _fsTextView.layer.borderColor = SQColor3DA59D.CGColor;
        _fsTextView.maxLength = 100;
    }
    return _fsTextView;
}
- (SQCustomButton *)addButton{
    if (!_addButton) {
        _addButton = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(0, 0) midmargin:0];
        _addButton.backgroundColor = SQColor3DA59D;
        _addButton.textColor = SQColor(@"#FFFFFF");
        _addButton.layer.cornerRadius = 25;
        _addButton.layer.masksToBounds = YES;
        _addButton.text = SQNSLocalString(@"确认");
        _addButton.font = FONT_MEDIUM(16);
    }
    return _addButton;
}

@end
